/**
 * 
 */
package test;

import java.awt.Image;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;

/**
 * @author patrick
 *
 */
public class Craft {
	
	private String craft = "craft.png";

	/**
	 * "move"-variable: defines the speed in x-direction
	 * */
    private int dx;
    /**
	 * "move"-variable: defines the speed in y-direction
	 * */
    private int dy;
    private int x;
    private int y;
    private Image image;
    
    public Craft () {
    	ImageIcon ii = new ImageIcon(this.getClass().getResource(craft));
    	image = ii.getImage();
    	x = 40;
    	y = 60;
    }
    
    /**
     * move the character
     * */
    public void move() {
        x += dx;
        y += dy;
    }

	/**
	 * @return the x
	 */
	public int getX() {
		return x;
	}

	/**
	 * @return the y
	 */
	public int getY() {
		return y;
	}

	/**
	 * @return the image
	 */
	public Image getImage() {
		return image;
	}
	
	public void keyPressed(KeyEvent e){
		int key = e.getKeyCode();
		
		if(key == KeyEvent.VK_LEFT)
			dx = -1;
		
		if(key == KeyEvent.VK_RIGHT)
			dx = 1;
		
		if(key == KeyEvent.VK_UP)
			dy = -1;
		
		if(key == KeyEvent.VK_DOWN)
			dy = 1;
	}
	
	public void keyReleased(KeyEvent e){
		int key = e.getKeyCode();
		
		if(key == KeyEvent.VK_LEFT)
			dx = 0;
		
		if(key == KeyEvent.VK_RIGHT)
			dx = 0;
		
		if(key == KeyEvent.VK_UP)
			dy = 0;
		
		if(key == KeyEvent.VK_DOWN)
			dy = 0;
	}
    
 
}

